#python中的类和对象
class Date:
    #类的构造函数，第一个参数必须为 self
    def __init__(self, year = 1, month = 1, day = 1):
        self.year = year
        self.month = month
        self.day = day

    def Print(self):
        print(f"{self.year} - {self.month} - {self.day}")

    #在 python 类中重载 > 运算符
    def __gt__(self, date):
        if self.year > date.year:
            return True
        if self.month > date.month:
            return True
        if self.day > date.day:
            return True
        else:
            return False

    #重载 == 运算符
    def __eq__(self, date):
        return self.year == date.year and self.month == date.month and self.day == date.day

    #重载 >= 运算符
    def __ge__(self, date):
        return self > date or self == date

    #重载 != 运算符
    def __ne__(self, date):
        return not(self == date)

    #重载 < 运算符
    def __lt__(self, date):
        return not(self >= date)

    #重载 <= 运算符
    def __le__(self, date):
        return not(self > date)


#实例化对象
d1 = Date(2022, 1, 1)
d2 = Date(2022, 1, 2)
d1.Print()#调用 Print 方法
d2.Print()
print(d1 < d2)
print(d1 <= d2)
print(d1 > d2)
print(d1 >= d2)
print(d1 == d2)
print(d1 != d2)

#类的继承
class Person:
    def __init__(self, name = "zhangsan", sex = "女", age = 18):
        self.name = name
        self.sex = sex
        self.age = age

    def Run(self):
        print("跑步")

    def Eat(self):
        print("吃饭")

#让 student 类继承 Person 类
class Student(Person):
    def __init__(self, name = "lisi", sex = "男", number = "11111111", age = 18):
        #super()会返回父类的对象，借助父类的构造函数初始化
        super().__init__(name, sex, age)
        self.number = number

    def Print(self):
        print(f"姓名:{self.name}, 性别:{self.sex}, 学号:{self.number}, 年龄:{self.age}")

    def Study(self):
        print("学习")

    def Eaxm(self):
        print("考试")

s1 = Student("wangwu", number = "2025010201")
s1.Print()
#子类中没有的方法，会去调用父类的方法
s1.Run()
s1.Eat()
#子类中有的方法，会去调用子类自己的方法
s1.Eaxm()
s1.Study()




